
package pri.syl.xiaowu.websocket.netty.server.handler.core.factory.execution;

import pri.syl.xiaowu.websocket.core.exception.WebsocketException;
import pri.syl.xiaowu.websocket.core.template.WebsocketRouteTemplate;
import pri.syl.xiaowu.websocket.netty.server.handler.core.factory.HandshakeFactory;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.FullHttpRequest;

/**
 * 握手工厂执行
 */
public class HandshakeFactoryExecution {
    private HandshakeFactoryExecution() {
    }

    public static void upgradeWebsocket(Channel channel, FullHttpRequest request, int maxFramePayloadLength, int readTimeoutMilli) throws WebsocketException {
        String requestUri = request.uri();
        WebsocketRouteTemplate routeTemplate = HandshakeFactory.pathValidation(requestUri);
        HandshakeFactory.handshake(request, maxFramePayloadLength, channel);
        HandshakeFactory.upgradePipeline(routeTemplate, readTimeoutMilli, channel, request);
    }
}
